﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tracker.Models.BLL;
using tracker.Models;
using System.Web.Script.Serialization;
using System.Data;
using Newtonsoft.Json;
namespace tracker.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {       
        [SessionExpireFilterAttribute] 
        public ActionResult Index()
        {
            // Set permission for current user login
            int permission = 0;
            int grouplogin = 1;
           
            int iGroupID = Int16.Parse(Session[Common.USER_GROUPID].ToString());
            switch (iGroupID)
            {
                case 1:                    
                    permission = 1;
                    grouplogin = 0;
                    break;
                case 2:
                     permission = 2;
                    grouplogin = 2;
                    break;
                case 3:
                     permission = 2;
                    grouplogin = 1;
                    break;
                case 4:
                     permission = 2;
                    grouplogin = 1;
                    break;
            }
            ViewData["permission"] = permission;
            ViewData["grouplogin"] = grouplogin;
            return View();
        }
        [CallAjaxFilter]
        public string getName()
        {
            return "hello";
        }
        public int Fail()
        {
            return 0;
        }
        [CallAjaxFilter]
        public int logout()
        {
            HttpContext.Session[Common.USER] = null;
            return 1;
        }

        //public JsonStringResult driverTest()
        //{
        //   //return new JsonStringResult("{data:[name:1123]}");
        //   // return new JsonStringResult("{'driver_id':2,'driver_name':'Le Duc Hau','driver_age':'2013-04-11','driver_email':'haule.cntt@gmail.com','driver_phone':'0938020920','driver_cellphone':'0938020920','driver_license_model1':null,'driver_license_model2':null,'driver_license_model3':null,'driver_creator_type':null,'driver_account':null,'driver_remarks':''},{'driver_id':3,'driver_name':'Nguy?n Thu?ng Hi?n','driver_age':'2013-04-04','driver_email':'hienthuong@gmail.com','driver_phone':'01234584','driver_cellphone':'120122222','driver_license_model1':null,'driver_license_model2':null,'driver_license_model3':null,'driver_creator_type':null,'driver_account':null,'driver_remarks':'Tài x? gi?i 2'}");
        //    DataSet ds = new UserDAL().getByUserName("phu");

        //    //string json = JsonConvert.SerializeObject(ds.Tables[0], Formatting.Indented);
        //    return new JsonStringResult("{data:[{'driver_id':2,'driver_name':'Le Duc Hau','driver_age':'2013-04-11','driver_email':'haule.cntt@gmail.com','driver_phone':'0938020920','driver_cellphone':'0938020920','driver_license_model1':null,'driver_license_model2':null,'driver_license_model3':null,'driver_creator_type':null,'driver_account':null,'driver_remarks':''},{'driver_id':3,'driver_name':'Nguy?n Thu?ng Hi?n','driver_age':'2013-04-04','driver_email':'hienthuong@gmail.com','driver_phone':'01234584','driver_cellphone':'120122222','driver_license_model1':null,'driver_license_model2':null,'driver_license_model3':null,'driver_creator_type':null,'driver_account':null,'driver_remarks':'Tài x? gi?i 2'},{'driver_id':4,'driver_name':'asd','driver_age':'2013-11-08','driver_email':'ad@amam.com','driver_phone':'123123123','driver_cellphone':'123123123','driver_license_model1':null,'driver_license_model2':null,'driver_license_model3':null,'driver_creator_type':null,'driver_account':null,'driver_remarks':'asdad'}]}");
        //}
        
    }

}
//